<template>
    <div id="dr24">
        <Breadcrumb style="margin-bottom: 10px">
            <BreadcrumbItem to="/superAdmin">首页</BreadcrumbItem>
            <BreadcrumbItem>运营分析平台</BreadcrumbItem>
            <BreadcrumbItem>视频微信沟通记录</BreadcrumbItem>
        </Breadcrumb>
        <div style="padding-right: 20px">
            微信:
            <Select v-model="type" style="width:200px;">
                <Option v-for="item in typeList" :value="item.value" :key="item.value">{{ item.label }}</Option>
            </Select> &nbsp;
            <DatePicker v-model="startTime" type="date" placeholder="选择开始时间" style="width: 150px"></DatePicker>
            至
            <DatePicker v-model="endTime" type="date" placeholder="选择结束时间" style="width: 150px"></DatePicker>
            &nbsp;
            <Button type="info" @click="search()">查询</Button>

        </div>

        <Table style="margin-top: 10px" :maxWidth="1000" :minWidth="10" stripe :columns="columns" :data="data"
               v-if="data&&data.length>0"></Table>

        <br>
        <Page :total="pageTotal" :current="curPage" @on-change="pageChange"
              style="display: inline-block;padding-top: 10px;padding-bottom: 10px" show-elevator
              v-if="data&&data.length>0"/>

        <div style="padding-left: 10px;position:relative ;display: inline-block;height: 52px;line-height: 52px;top: -12px">
            总计 {{dataTotal}} 条数据
        </div>


        <div id="loading" v-if="loading">
            <div class="spinner">
                <div class="double-bounce1"></div>
                <div class="double-bounce2"></div>
            </div>
        </div>


        <Modal v-model="modeBool">
            <div slot="header" style="text-align: center;font-size: 18px;font-weight: 600">处理</div>
            <div style="text-align:left;">
                <div style="margin-top: 10px">
                    <span style="font-size: 16px ;color: #f00">是否加微信:&nbsp;</span>
                    <RadioGroup v-model="vxType">
                        <Radio label="是" style="font-size: 16px;"></Radio>
                        <Radio label="否" style="font-size: 16px;"></Radio>
                    </RadioGroup>
                </div>
                <div style="margin-top: 10px">
                    <span style="font-size: 16px ;color: #f00">是否通过:&nbsp;</span>
                    <RadioGroup v-model="ispass">
                        <Radio label="是" style="font-size: 16px;"></Radio>
                        <Radio label="否" style="font-size: 16px;"></Radio>
                    </RadioGroup>
                </div>
                <div style="margin-top: 10px">
                    <span style="font-size: 16px ;color: #f00">是否参加活动:&nbsp;</span>
                    <RadioGroup v-model="joinType">
                        <Radio label="是" style="font-size: 16px;"></Radio>
                        <Radio label="否" style="font-size: 16px;"></Radio>
                    </RadioGroup>
                </div>

            </div>
            <div slot="footer">
                <Button type="info" @click="modeBool=false">取消</Button>
                <Button type="info" @click="change()">确定</Button>
            </div>
        </Modal>

    </div>
</template>
<script type="text/ecmascript-6">
    import sessionUtils from '../../model/sessionUtils';
    import ipServer from '../../model/ip';
    import Axios from 'axios';

    export default {
        data() {
            return {
                vxType: "否",
                ispass: "否",
                joinType: "否",
                selectMobile: "",
                dataTotal: 0,
                reffer: "",
                endTime: "",
                startTime: "",
                type: "2",
                typeList: [
                    {
                        value: '2',
                        label: '全部'
                    },
                    {
                        value: '1',
                        label: '是'
                    },
                    {
                        value: '0',
                        label: '否'
                    },],
                loading: false,
                modeData: {},
                modeBool: false,
                pageTotal: 0,
                curPage: 0,
                columns: [
                    {
                        title: '手机号码',
                        key: 'mobile',
                        width: 120
                    },
                    {
                        title: '注册时间',
                        key: 'registeTime1',
                        width: 100
                    },
                    {
                        title: '拨通时间',
                        key: 'callTime1',
                        width: 100
                    },
                    {
                        title: '用户认可度',
                        key: 'recognition1',
                    },
                    {
                        title: '参与目的',
                        key: 'takePartIn1',
                    },
                    {
                        title: '是否加微信',
                        key: 'isWeChat1',
                        width: 120
                    },
                    {
                        title: '是否通过',
                        key: 'isPass1',
                        width: 120
                    }, {
                        title: '是否参与活动',
                        key: 'isJoin1',
                        width: 150
                    }, {
                        title: '处理',
                        key: 'action',
                        width: 100,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.modeBool = true;
                                            this.modeData = params;
                                        }
                                    }
                                }, "编辑"),
                            ]);
                        }
                    }
                ],
                data: []
            }
        },
        mounted() {
            this.getData();
        },
        methods: {
            pageChange(page) {
                this.getData(page);
            },
            doChange() {
                this.ispass = "";
                this.vxType = "";
                this.joinType = "";
            }, change() {
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                param.append('userId', this.modeData.row.userId);

                if (this.vxType && this.ispass && this.joinType) {


                    if (this.vxType == "是")
                        param.append('isWeChat', "1");
                    if (this.vxType == "否")
                        param.append('isWeChat', "0");


                    if (this.ispass == "是")
                        param.append('isPass', "1");
                    if (this.ispass == "否")
                        param.append('isPass', "0");


                    if (this.joinType == "是")
                        param.append('isJoin', "1");
                    if (this.joinType == "否")
                        param.append('isJoin', "0");


                    this.loading = true;
                    Axios.post(ipServer + "video/updateStatusForWeChat", param)
                        .then(res => {
                            if (res.data.code == 0) {
                                sessionUtils.setSession("token", res.data.token);

                                if (this.vxType) {

                                    if (this.vxType == "是")
                                        this.data[this.modeData.index].isWeChat = 1;
                                    if (this.vxType == "否")
                                        this.data[this.modeData.index].isWeChat = 0;

                                    this.data[this.modeData.index].isWeChat1 = this.vxType;

                                }
                                if (this.ispass) {

                                    if (this.ispass == "是")
                                        this.data[this.modeData.index].isPass = 1;
                                    if (this.ispass == "否")
                                        this.data[this.modeData.index].isPass = 0;

                                    this.data[this.modeData.index].isPass1 = this.ispass;

                                }
                                if (this.joinType) {

                                    if (this.joinType == "是")
                                        this.data[this.modeData.index].isJoin = 1;
                                    if (this.joinType == "否")
                                        this.data[this.modeData.index].isJoin = 0;

                                    this.data[this.modeData.index].isJoin1 = this.joinType;

                                }


                                this.ispass = "否";
                                this.vxType = "否";
                                this.joinType = "否";

                                this.modeBool = false;
                            } else if (res.data.code == 3) {
                                sessionUtils.clear();
                                this.$router.push("/login");
                                this.$Message.info(res.data.msg);

                            } else {
                                this.$Message.info(res.data.msg);

                            }
                            this.loading = false;
                        })
                        .catch(err => {
                            this.loading = false;
                            this.$Message.info(err.toString());
                        });
                } else {
                    this.$Message.info("处理不能为空!");
                }


            }
            , search() {
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (this.type != 2)
                    param.append('isWeChat', this.type);
                if (this.startTime) {
                    param.append('startYearMonthDay', sessionUtils.DateToTime(this.startTime) + "");
                }
                if (this.endTime) {
                    param.append('endYearMonthDay', sessionUtils.DateToTime(this.endTime) + "");
                }
                this.loading = true;
                Axios.post(ipServer + "video/selectWeChatRecordInfos", param)
                    .then(res => {

                        if (res.data.code == 0) {

                            console.log("打印" + JSON.stringify(res));
                            sessionUtils.setSession("token", res.data.token);
                            for (var i = 0; i < res.data.data.result.length; i++) {
                                res.data.data.result[i].registeTime1 = sessionUtils.timestampToTime3(res.data.data.result[i].registeTime);
                                res.data.data.result[i].callTime1 = sessionUtils.timestampToTime3(res.data.data.result[i].callTime);
                                /*  if (res.data.data.result[i].callStatus == "0") {
                                      res.data.data.result[i].callStatus1 = "未拨打";
                                  }
                                  if (res.data.data.result[i].callStatus == "1") {
                                      res.data.data.result[i].callStatus1 = "未接通";
                                  }
                                  if (res.data.data.result[i].callStatus == "2") {
                                      res.data.data.result[i].callStatus1 = "已接通";
                                  }*/

                                if (res.data.data.result[i].recognition == "0") {
                                    res.data.data.result[i].recognition1 = "待处理";
                                }
                                if (res.data.data.result[i].recognition == "1") {
                                    res.data.data.result[i].recognition1 = "信任";
                                }
                                if (res.data.data.result[i].recognition == "2") {
                                    res.data.data.result[i].recognition1 = "一般";
                                }
                                if (res.data.data.result[i].recognition == "3") {
                                    res.data.data.result[i].recognition1 = "很忙";
                                }
                                if (res.data.data.result[i].recognition == "4") {
                                    res.data.data.result[i].recognition1 = "不信任";
                                }
                                if (res.data.data.result[i].recognition == "5") {
                                    res.data.data.result[i].recognition1 = "伪用户";
                                }


                                if (res.data.data.result[i].takePartIn == "0") {
                                    res.data.data.result[i].takePartIn1 = "待处理";
                                }
                                if (res.data.data.result[i].takePartIn == "1") {
                                    res.data.data.result[i].takePartIn1 = "不信任";
                                }
                                if (res.data.data.result[i].takePartIn == "2") {
                                    res.data.data.result[i].takePartIn1 = "赚钱";
                                }
                                if (res.data.data.result[i].takePartIn == "3") {
                                    res.data.data.result[i].takePartIn1 = "信任";
                                }

                                if (res.data.data.result[i].isWeChat == "1") {
                                    res.data.data.result[i].isWeChat1 = "是";
                                }
                                if (res.data.data.result[i].isWeChat == "0") {
                                    res.data.data.result[i].isWeChat1 = "否";
                                }


                                if (res.data.data.result[i].isPass == "1") {
                                    res.data.data.result[i].isPass1 = "是";
                                }
                                if (res.data.data.result[i].isPass == "0") {
                                    res.data.data.result[i].isPass1 = "否";
                                }

                                if (res.data.data.result[i].isJoin == "1") {
                                    res.data.data.result[i].isJoin1 = "是";
                                }
                                if (res.data.data.result[i].isJoin == "0") {
                                    res.data.data.result[i].isJoin1 = "否";
                                }


                            }
                            this.pageTotal = res.data.data.dataTotal;
                            this.dataTotal = res.data.data.dataTotal;
                            this.data = res.data.data.result;
                            this.curPage = res.data.data.curPage;
                            if (this.data.length == 0)
                                this.$Message.info("查询数据不存在!");
                        } else if (res.data.code == 3) {
                            sessionUtils.clear();
                            this.$router.push("/login");
                            this.$Message.info(res.data.msg);
                        } else {
                            this.$Message.info(res.data.msg);
                        }
                        this.loading = false;
                    })
                    .catch(err => {
                        this.loading = false;
                        this.$Message.info(err);
                    });
            },
            getData(page) {
                var param = new URLSearchParams();
                param.append('mobile', sessionUtils.getSession("mobile"));
                param.append('token', sessionUtils.getSession("token"));
                if (this.type != 2)
                    param.append('isWeChat', this.type);
                if (this.startTime) {
                    param.append('startYearMonthDay', sessionUtils.DateToTime(this.startTime) + "");
                }
                if (this.endTime) {
                    param.append('endYearMonthDay', sessionUtils.DateToTime(this.endTime) + "");
                }
                if (page) {
                    param.append('pageId', page + "");
                }
                this.loading = true;
                Axios.post(ipServer + "video/selectWeChatRecordInfos", param)
                    .then(res => {
                        if (res.data.code == 0) {
                            console.log("打印" + JSON.stringify(res));
                            sessionUtils.setSession("token", res.data.token);
                            for (var i = 0; i < res.data.data.result.length; i++) {
                                res.data.data.result[i].registeTime1 = sessionUtils.timestampToTime3(res.data.data.result[i].registeTime);
                                res.data.data.result[i].callTime1 = sessionUtils.timestampToTime3(res.data.data.result[i].callTime);
                                /*  if (res.data.data.result[i].callStatus == "0") {
                                     res.data.data.result[i].callStatus1 = "未拨打";
                                 }
                                 if (res.data.data.result[i].callStatus == "1") {
                                     res.data.data.result[i].callStatus1 = "未接通";
                                 }
                                 if (res.data.data.result[i].callStatus == "2") {
                                     res.data.data.result[i].callStatus1 = "已接通";
                                 }*/

                                if (res.data.data.result[i].recognition == "0") {
                                    res.data.data.result[i].recognition1 = "待处理";
                                }
                                if (res.data.data.result[i].recognition == "1") {
                                    res.data.data.result[i].recognition1 = "信任";
                                }
                                if (res.data.data.result[i].recognition == "2") {
                                    res.data.data.result[i].recognition1 = "一般";
                                }
                                if (res.data.data.result[i].recognition == "3") {
                                    res.data.data.result[i].recognition1 = "很忙";
                                }
                                if (res.data.data.result[i].recognition == "4") {
                                    res.data.data.result[i].recognition1 = "不信任";
                                }
                                if (res.data.data.result[i].recognition == "5") {
                                    res.data.data.result[i].recognition1 = "伪用户";
                                }


                                if (res.data.data.result[i].takePartIn == "0") {
                                    res.data.data.result[i].takePartIn1 = "待处理";
                                }
                                if (res.data.data.result[i].takePartIn == "1") {
                                    res.data.data.result[i].takePartIn1 = "不信任";
                                }
                                if (res.data.data.result[i].takePartIn == "2") {
                                    res.data.data.result[i].takePartIn1 = "赚钱";
                                }
                                if (res.data.data.result[i].takePartIn == "3") {
                                    res.data.data.result[i].takePartIn1 = "信任";
                                }

                                if (res.data.data.result[i].isWeChat == "1") {
                                    res.data.data.result[i].isWeChat1 = "是";
                                }
                                if (res.data.data.result[i].isWeChat == "0") {
                                    res.data.data.result[i].isWeChat1 = "否";
                                }


                                if (res.data.data.result[i].isPass == "1") {
                                    res.data.data.result[i].isPass1 = "是";
                                }
                                if (res.data.data.result[i].isPass == "0") {
                                    res.data.data.result[i].isPass1 = "否";
                                }

                                if (res.data.data.result[i].isJoin == "1") {
                                    res.data.data.result[i].isJoin1 = "是";
                                }
                                if (res.data.data.result[i].isJoin == "0") {
                                    res.data.data.result[i].isJoin1 = "否";
                                }

                            }
                            this.pageTotal = res.data.data.dataTotal;
                            this.dataTotal = res.data.data.dataTotal;
                            this.data = res.data.data.result;
                            this.curPage = res.data.data.curPage;
                            if (this.data.length == 0)
                                this.$Message.info("查询数据不存在!");
                        } else if (res.data.code == 3) {
                            sessionUtils.clear();
                            this.$Message.info(res.data.msg);
                            this.$router.push("/login");
                        } else {
                            this.$Message.info(res.data.msg);
                        }
                        this.loading = false;
                    })
                    .catch(err => {
                        this.loading = false;
                        this.$Message.info(err);
                    });
            }
        }
    }
</script>


<style scoped>
    @import "../../assets/css/loading.css";

</style>